package com.wfs.suanfa.lock;


import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author: wfs
 * @Date: 2021/1/6 08:21
 * @Description:
 */
public class ReentrantLock2 {
    public static void main(String[] args) {
        Lock lock=new ReentrantLock();
        Thread t1=new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                try {
                    System.out.println("线程T1开始执行");
                    Thread.sleep(1000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
            }
        });
        Thread t2=new Thread(new Runnable() {
            @Override
            public void run() {
                lock.lock();
                try {
                    Thread.sleep(1000L);
                    System.out.println("线程T2开始执行");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }finally {
                    lock.unlock();
                }
            }
        });
        t1.start();
        t2.start();

    }
    private void m(){

    }
}
